import { SubjectServiceDefinition, ListTopicsRequest, ListTopicsResponse} from "@/types/proto/api/v1/subject_service";
import {SetFavorSubjectRequest} from "@/types/proto/api/v1/subject_service";
import {ListSubjectsRequest,ListFavorSubjectsRequest,ListSubjectsResponse, Subject, DeleteSubjectRequest} from "@/types/proto/api/v1/subject_service";
import {GetSubjectRequest, GetTopicRequest, CreateSubjectRequest, UpdateSubjectRequest,DeleteSubjectTopicsRequest, CreateTopicRequest, CreateTopicResponse} from "@/types/proto/api/v1/subject_service";

import { subjectServiceClient} from "./grpcweb_auth";
import {useUserStore} from "@/store/user"
import { TopicDef } from "@/types/proto/common/common";
import { Empty } from "@/types/proto/google/protobuf/empty";

  export async function ListTopics(data: ListTopicsRequest): Promise<ListTopicsResponse> {
    try {  
        return subjectServiceClient.listTopics(data)
      } catch (error) {
        console.error('gRPC request failed:', error);
        throw error;
    }
  }

  export async function ListSubjects(data: ListSubjectsRequest): Promise<ListSubjectsResponse> {
    try {  
      return subjectServiceClient.listSubjects(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function GetSubject(data: GetSubjectRequest): Promise<Subject> {
    try {  
      return subjectServiceClient.getSubject(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function GetTopic(data: GetTopicRequest): Promise<TopicDef> {
    try {  
      return subjectServiceClient.getTopic(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function DeleteSubject(data: DeleteSubjectRequest): Promise<Empty> {
    try {  
      return subjectServiceClient.deleteSubject(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function DeleteSubjectTopics(data: DeleteSubjectTopicsRequest): Promise<Empty> {
    try {  
      return subjectServiceClient.deleteSubjectTopics(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }


  export async function CreateSubject(data: CreateSubjectRequest): Promise<Subject> {
    try {  
      return subjectServiceClient.createSubject(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function CreateTopic(data: CreateTopicRequest): Promise<CreateTopicResponse> {
    try {  
      return subjectServiceClient.createTopic(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function UpdateSubject(data: UpdateSubjectRequest): Promise<Subject> {
    try {  
      return subjectServiceClient.updateSubject(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function ListFavorSubjects(data: ListFavorSubjectsRequest): Promise<ListSubjectsResponse> {
    try {  
      return subjectServiceClient.listFavorSubjects(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }

  export async function SetFavorSubject(data: SetFavorSubjectRequest): Promise<Subject> {
    try {  
      return subjectServiceClient.setFavorSubject(data)
    } catch (error) {
      console.error('gRPC request failed:', error);
      throw error;
    }
  }